package com.kede.app.rest;

import com.kede.annotation.Log;
import com.kede.app.domain.ZhiGoodValidFail;
import com.kede.app.service.ZhiGoodValidFailService;
import com.kede.app.service.dto.ZhiGoodValidFailQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
* @author Pr.li
* @date 2023-10-14
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "validFail管理")
@RequestMapping("/api/zhiGoodValidFail")
public class ZhiGoodValidFailController {

    private final ZhiGoodValidFailService zhiGoodValidFailService;

    /**
     * 导出数据
     **/
    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('zhiGoodValidFail:list')")
    public void exportZhiGoodValidFail(HttpServletResponse response, ZhiGoodValidFailQueryCriteria criteria) throws IOException {
        zhiGoodValidFailService.download(zhiGoodValidFailService.queryAll(criteria), response);
    }

    /**
    * 查询validFail
    **/
    @GetMapping
    @Log("查询validFail")
    @ApiOperation("查询validFail")
    @PreAuthorize("@el.check('zhiGoodValidFail:list')")
    public ResponseEntity<Object> queryZhiGoodValidFail(ZhiGoodValidFailQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(zhiGoodValidFailService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    /**
    * 新增validFail
    **/
    @PostMapping
    @Log("新增validFail")
    @ApiOperation("新增validFail")
    @PreAuthorize("@el.check('zhiGoodValidFail:add')")
    public ResponseEntity<Object> createZhiGoodValidFail(@Validated @RequestBody ZhiGoodValidFail resources){
        return new ResponseEntity<>(zhiGoodValidFailService.create(resources),HttpStatus.CREATED);
    }


    /**
    * 修改validFail
    **/
    @PutMapping
    @Log("修改validFail")
    @ApiOperation("修改validFail")
    @PreAuthorize("@el.check('zhiGoodValidFail:edit')")
    public ResponseEntity<Object> updateZhiGoodValidFail(@Validated @RequestBody ZhiGoodValidFail resources){
        zhiGoodValidFailService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }


    /**
    * 删除validFail
    **/
    @DeleteMapping
    @Log("删除validFail")
    @ApiOperation("删除validFail")
    @PreAuthorize("@el.check('zhiGoodValidFail:del')")
    public ResponseEntity<Object> deleteZhiGoodValidFail(@RequestBody Integer[] ids) {
        zhiGoodValidFailService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}